
{%- if vk_pixels -%}
  
  <!-- Top.Mail.Ru counter -->
  <script type="text/javascript">
    (function(){
        var _tmr = window._tmr || (window._tmr = []);
        const pixels = {{vk_pixels|json}};
        function triggerPixels(event, data) {
          pixels.forEach(function(pixid) {
              _tmr.push({ type: 'reachGoal', id: pixid, goal: event,...data});
          });
        }
        window['TOP_GLOBAL_CALLBACK_LAYER'].register({
          'page_view': function() {
            triggerPixels('pageView');
          },
          'view_content': function() {
              triggerPixels('ViewContent');
          },
          'search': function() {
              triggerPixels('Search');
          },
          'purchase': function() {
            {% if order.id %}
            {% capture bigo_pixels_order_id %}bigo_pixels_{{order.id}}{% endcapture %}
            {% get_cache key={bigo_pixels_order_id} var_name=bigo_pixels_status%}
            {% if bigo_pixels_status ==0 %}
                triggerPixels('Purchase',{value:order.total_price ,params:{product_id: order.order_number} });
            {% endif %}
            {% endif %}
          },
          'begin_checkout': function() {
              triggerPixels('InitiateCheckout');
          },
          'add_to_cart': function(ecdata) {
            {%- if storeConfig.vkontakte_enable_ga == 1 -%}
              triggerPixels('AddToCart',{ value: ecdata['ec_data_price'] * ecdata['ec_data_quantity'],params:{product_id: ecdata['ec_data_id']} });
            {%- else -%}
              triggerPixels('AddToCart');
            {%- endif -%}
          },
          'add_to_wishlist': function() {
            triggerPixels('AddToWishlist');
          },
          'sign_up': function() {
            triggerPixels('CompleteRegistration');
          }
      });
    })();

    (function (d, w, id) {
      if (d.getElementById(id)) return;
      var ts = d.createElement("script"); ts.type = "text/javascript"; ts.async = true; ts.id = id;
      ts.src = "https://top-fwz1.mail.ru/js/code.js";
      var f = function () {var s = d.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ts, s);};
      if (w.opera == "[object Opera]") { d.addEventListener("DOMContentLoaded", f, false); } else { f(); }
    })(document, window, "tmr-code");
  </script>
  {% for pixel in vk_pixels %}
  <noscript><div><img src="https://top-fwz1.mail.ru/counter?id={{pixel}};js=na" style="position:absolute;left:-9999px;" alt="Top.Mail.Ru" /></div></noscript>
  {% endfor %}
{%- endif -%}